﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using XNACamera;

namespace PlaneGame
{
    class Avion : GameModel
    {
        Vector3 _position; //position du centre de l’avion
        float _roulis, _tangage, _lacet; //donnent l’orientation de l’avion
        float _vitesse; //vitesse de l’avion
        float _ascent;

        public Vector3 Position
        {
            get
            {
                return _position;
            }

            set
            {
                _position = value;
            }
        }

        public float Roulis
        {
            get
            {
                return _roulis;
            }

            set
            {
                _roulis = value;
            }
        }

        public float Tangage
        {
            get
            {
                return _tangage;
            }

            set
            {
                _tangage = value;
            }
        }

        public float Lacet
        {
            get
            {
                return _lacet;
            }

            set
            {
                _lacet = value;
            }
        }

        public float Vitesse
        {
            get
            {
                return _vitesse;
            }

            set
            {
                _vitesse = value;
            }
        }

        public float Ascent
        {
            get
            {
                return _ascent;
            }

            set
            {
                _ascent = value;
            }
        }

        public override Matrix World
        {
            get
            {
                return (Matrix.CreateFromYawPitchRoll(_lacet, _tangage, _roulis) * Matrix.CreateTranslation(_position));
            }
        }

        public Avion(Game game)
            : base(game, "GeeBee2")
        {
            _lacet = 0;
            _roulis = 0;
            _tangage = 0;
            _position = new Vector3(0);
            _vitesse = 0;
        }

        public override void Update(GameTime gameTime)
        {
            Vector3 _direction = new Vector3(0, 0, -1);
            _direction = Vector3.Transform(_direction, Matrix.CreateFromYawPitchRoll(_lacet, _tangage, _roulis));
            _position += _direction * _vitesse;
            //Console.WriteLine(" ascent = " + _ascent + " -- Tangage = " + Tangage);

            //Console.WriteLine("roulis = " + Roulis);
            


            _ascent *= 0.95f;

            

            ((XNACamera.CameraSpherique)Camera).Cible = Position;
            ((XNACamera.CameraSpherique)Camera).Phi = -Tangage + MathHelper.Pi / 6.0f + _ascent * 0.6f;
            ((XNACamera.CameraSpherique)Camera).Theta = -Lacet + MathHelper.PiOver2;
            base.Update(gameTime);
        }
    }
}
